package dev.ece.suit.loader.models.fbx;

import java.io.IOException;

import dev.ece.util.io.LittleEndianInputStream;

public class FBXHeader {

	private byte[] magic;
	
	private byte[] reserved;
	
	private int version;

	private FBXHeader() {}
	
	public static FBXHeader loadFbxHeader(LittleEndianInputStream input) throws IOException {
		FBXHeader header = new FBXHeader();
		header.magic = new byte[21];
		input.read(header.magic);
		header.reserved = new byte[2];
		input.read(header.reserved);
		header.version = input.readInt();
		return header;
	}
	
	public long readElementOffset(LittleEndianInputStream input) throws IOException {
		if(version >= 7500) {
			return input.readUnsignedInt();
		} else {
			return input.readInt();
		}
	}
	
	public int blockSentinelLength() {
		return version >= 7500 ? 25 : 13;
	}
	
	public byte[] getMagic() {
		return magic;
	}

	public byte[] getReserved() {
		return reserved;
	}

	public int getVersion() {
		return version;
	}
	
}
